package com.czy.daishusys.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.czy.daishusys.R;
import com.czy.daishusys.entity.StoreBooks;
import com.czy.daishusys.utils.PhoneUtils;
import com.czy.daishusys.utils.glide.GlideUtils;


import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by hedepu on 2017/11/27.
 */
public class ExpandableStaffAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {
    private static final String TAG = ExpandableStaffAdapter.class.getSimpleName();

    public static final int TYPE_LEVEL_0 = 0;
    public static final int TYPE_LEVEL_1 = 1;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public ExpandableStaffAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_LEVEL_0, R.layout.item_store_books_group);
        addItemType(TYPE_LEVEL_1, R.layout.item_store_child_recycler);

    }


    @Override
    protected void convert(final BaseViewHolder holder, final MultiItemEntity item) {
        switch (holder.getItemViewType()) {
            case TYPE_LEVEL_0:
                final StoreBooks storeBooks = (StoreBooks) item;

                holder.setText(R.id.tv_group_name, storeBooks.getGroupName())
                        .setText(R.id.tv_group_count, storeBooks.getSubItems().size() + "")
                        .setImageResource(R.id.iv_group_status, storeBooks.isExpanded() ? R.mipmap.icon_arrow_down : R.mipmap.icon_arrow_right);
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getAdapterPosition();
                        if (storeBooks.isExpanded()) {
                            collapse(pos);
                        } else {
//                            if (pos % 3 == 0) {
//                                expandAll(pos, false);
//                            } else {
                            expand(pos);
//                            }
                        }
                    }
                });
//
                break;
            case TYPE_LEVEL_1:
                StoreBooks.StoreBooksDetail storeBooksDetail = (StoreBooks.StoreBooksDetail) item;
                holder.setText(R.id.tv_item_name, storeBooksDetail.getEmployeesName())
                        .setText(R.id.tv_item_following_msg, storeBooksDetail.getGroupCount() + "");
//                holder.addOnClickListener(R.id.linear_content_layout);
                //添加数据
                GlideUtils.loadImage(mContext, storeBooksDetail.getUserLogo(), (CircleImageView) holder.getView(R.id.iv_item_avatar), new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                    @Override
                    public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                    }

                    @Override
                    public void onLoadingError(String source, Exception e) {

                    }
                }, R.mipmap.icon_order_member_default, R.mipmap.icon_order_member_default);
                break;

        }
    }
}
